<template>
  <div class="main">
    <section>
      <el-table :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border highlight-current-row>
        <el-table-column align="center" label="系统参数名" prop="descr"></el-table-column>
        <el-table-column align="center" label="修改时间" prop="updatedAt"></el-table-column>
        <el-table-column align="center" label="值" prop="value">
          <template slot-scope="scope">
            <el-input v-model="scope.row.value"></el-input>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="100">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" plain @click="updateParams(scope.row)">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
    </section>
  </div>
</template>

<script>
import { getSystemTime, updateSystemTime } from '@/api/bizhibo'
export default {
  name: 'systemset',
  data() {
    return {
      list: [],
      listLoading: false
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      this.getData()
    },
    async getData() {
      try {
        this.listLoading = true
        const { data } = await getSystemTime()
        this.listLoading = false
        this.list = data
      } catch (error) {
        console.log(error)
        this.listLoading = false
      }
    },
    // 修改值
    async updateParams(val) {
      try {
        const { data, code } = await updateSystemTime(val)
        if (code === 200) {
          this.$message.success('操作成功')
          this.getData()
        }
      } catch (error) {
        this.$message.error('操作失败')
        console.log(error)
      }
    }
  }
}
</script>

<style></style>
